package cn.wolfcode.business.controller;

import cn.wolfcode.business.domain.BusServiceItem;
import cn.wolfcode.business.service.ServiceItemService;
import cn.wolfcode.common.core.controller.BaseController;
import cn.wolfcode.common.core.domain.AjaxResult;
import cn.wolfcode.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/business/serviceItem")
public class ServiceItemController extends BaseController {
    @Autowired
    private ServiceItemService serviceItemService;

    @GetMapping("/list")
    public TableDataInfo list(BusServiceItem serviceItem){
        startPage();
        List<BusServiceItem> busServiceItems = serviceItemService.list(serviceItem);
        return getDataTable(busServiceItems);
    }
    @GetMapping("/{id}")
    public AjaxResult get(@PathVariable Long id){
        return AjaxResult.success(serviceItemService.getById(id));
    }

    @PostMapping
    public AjaxResult save(@RequestBody BusServiceItem serviceItem){
        return  toAjax(serviceItemService.save(serviceItem));
    }

    @PutMapping
    public AjaxResult update(@RequestBody BusServiceItem serviceItem){
        return toAjax(serviceItemService.update(serviceItem));
    }

    @PatchMapping(value = "/{id}",headers = "cmd=on")
    public AjaxResult saleOnHandle(@PathVariable Long id){
        return toAjax(serviceItemService.saleOnHandle(id));
    }

    @PatchMapping(value = "/{id}",headers = "cmd=down")
    public AjaxResult saleDownHandle(@PathVariable Long id){
        return toAjax(serviceItemService.saleDownHandle(id));
    }
    @GetMapping(value = "/list",headers ="cmd=list")
    public AjaxResult getList(BusServiceItem serviceItem){
        List<BusServiceItem> list = serviceItemService.list(serviceItem);
        return AjaxResult.success(list);
    }

}
